package arithmetic.leetCode.yi;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yilin
 * Date: 2019-07-16
 * Time: 17:22
 */
public class MinStack {

    public static void main(String[] args) {
        MinStack stck = new MinStack();
        stck.push(-2);
        stck.push(0);
        stck.push(-3);
        System.out.println(stck.getMin());
        stck.pop();
        System.out.println(stck.top());
        System.out.println(stck.getMin());
    }

    private Stack<Integer> stack;
    private Stack<Integer> minStack;

    public MinStack() {
        stack = new Stack<Integer>();
        minStack = new Stack<Integer>();
    }

    public void push(int number) {
        if (minStack.isEmpty() || minStack.peek() > number) {
            minStack.push(number);
        }
        stack.push(number);
    }

    public int pop() {
        if (stack.peek().equals(minStack.peek())) {
            minStack.pop();
        }
        return stack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }


}
